#!/bin/bash

# == Awk Array ==
# awk array contains multiple index/value pairs. the index 
# doesn't need to be a continuous set of numbers 
# the index can be:
#   1. string
#   2. numbers
#
# NOTE: don't need to specify the size of the array 

# syntax:
#   array_name[string] = value
awk -f ./07_array_assign.awk
echo -e '\n'


# == Awk for loop == 
# syntax: 
#   for(iter in arrayname)
#       action;
awk -f ./07_array_for_loop.awk
echo -e '\n'
# 1. display in order by index ascendingly
# 2. [na] will display in first line.


# == Delete Array Element == 
# syntax:
#   delete arrayname[index]; # delete specified element
#   
#   delete arrayname; # delete all element

awk -f ./07_delete_array.awk
echo -e '\n'



# == Multi-dimensional-array == 
# syntax: 
#   item['i, j'] = val
# awk treat string 'i, j' as an index, and use it 

# syntax:
#   item[i,j] = val
# it use global variable 'SUBSEP' whitch default value is 'FS'(file seperator)
# or /034 in octal notation. awk transform i,j to i/034j, and convert i/034j to string
# then, treat "i/034j" as index
awk -f ./07_multi_dimensional_array.awk
echo -e '\n'

# change SUBSEP global variable

awk -f ./07_multi_dimensional_change_subsep.awk
echo -e '\n'



# == Array Sorting ==
# use function: asort(arrayname)
# asort default sort the array values and store them from index 1 to n, n is the size of
# array.
awk -f ./07_array_sort.awk
echo -e '\n'

# NOTE: asort sorts the array values. by default, asort follows alphabet order
# descending



# == index sorting == 
# we can take all the array indexes, sort them, and store them in a new 
# array using asorti
#   * asorti sorts the indexes(not the values) and stores them as values.
#   * if you secify asorti(state), you'll lose the original avlues.
awk -f ./07_array_index_sort.awk
echo -e "\n"


